package laba1.task3;

import java.util.Random;
import laba1.task2.Figure;
import static laba1.task2.Perimeter.perimeter;
import laba1.task2.Point;
import laba1.task2.Tetragon;
import laba1.task2.Triangle;

/**
 *
 * @author yakimovich
 */
public class ArrayOfFigures {

    /**
     * create an array of Figures and demonstration of polymorphism their methods
     *
     * @param args
     */
    public static void main(String[] args) {
        Figure[] figures = new Figure[10];
        Point[] points = new Point[4];
        Random random = new Random();

        //fill an array of Points random elements
        for (int i = 0; i < figures.length; i++) {
            for (int k = 0; k < points.length; k++) {
                points[k] = new Point(random.nextInt(1024), random.nextInt(1024));
            }
            //fill an array of Figures random elements
            Figure element = figures[i];
            element = (random.nextInt() % 2 == 0)
                    ? new Triangle(points[0], points[1], points[2])
                    : new Tetragon(points[0], points[1], points[2], points[3]);

            //display element index and its type
            System.out.println("i = " + i + " : " + element.getClass().getSimpleName());

            //display element
            element.draw();

            //display perimeter
            if (perimeter(element) == 0.0) {
                System.out.println("Perimeter is not found");
            } else {
                System.out.println("Perimeter: " + perimeter(element));
            }
            System.out.println();
        }
    }
}
